package com.example.dqnm.service.impl;

import com.example.dqnm.mapper.ProducttypeDao;
import com.example.dqnm.pojo.Producttype;
import com.example.dqnm.pojo.ProducttypeExample;
import com.example.dqnm.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class IndexServiceImpl implements IndexService {
    @Value("${sky.alioss.endpoint}")
    public String endpoint;
    @Value("${sky.alioss.bucket-name}")
    private String bucketName;
    @Value("${banner.count}")
    private Integer count;

    @Autowired
    private ProducttypeDao producttypeDao;
    @Override
    public ArrayList<String> findBanner() {
        ArrayList<String> bannerArray = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            bannerArray.add(getFullPath("banner-"+(i+1)+".png"));
        }
        return bannerArray;
    }

    @Override
    public ArrayList findProductType() {
        ProducttypeExample producttypeExample = new ProducttypeExample();
        List<Producttype> producttypes = producttypeDao.selectByExample(producttypeExample);
        return (ArrayList) producttypes;
    }

    public String getFullPath(String objectName) {
        //文件访问路径规则 https://BucketName.Endpoint/ObjectName
        StringBuilder stringBuilder = new StringBuilder("https://");
        stringBuilder
                .append(bucketName)
                .append(".")
                .append(endpoint)
                .append("/")
                .append(objectName);

        return stringBuilder.toString();
    }
}
